<template>

<block>
        

    <view class="personal">
            <UsrInfo :d="orderInfo" :art="topart"  />
            <view class="personal-content">
               
               
    
                                    <view class="ordertype-group"  v-if="islogin">
                                            <view class="ordertype-top">
                                                <text class="ordertype-title">我的订单</text>
                                                <navigator url="/pages/userbeautyOrderList/index?id=null" class="ordertype-more" open-type="reLaunch" hover-class="none">
                                                    全部订单  <image src="/static/images/allow-left.png" />
                                               
                                                </navigator>
                                            </view>
                                            <view class="ordertype-list">
                                                    <view @tap="tobeautyAllOrder('1')">
                                                        <image :src="require('./_static/images/personal_icon_01.png')" />
                                                        <text>待付款</text>
                                                    </view>
                                                    <view @tap="tobeautyAllOrder('0')">
                                                        <image :src="require('./_static/images/personal_icon_02.png')" />
                                                        <text>已付款</text>
                                                    </view>
                                                    <view @tap="tobeautyAllOrder('2')">
                                                        <image :src="require('./_static/images/personal_icon_03.png')" />
                                                        <text>已取消</text>
                                                    </view>
                                            </view>
                                    </view>


                                    <view class="personal-handle" v-if="islogin">

                                          

                                             <view class="item" v-if="orderInfo.salonState != 2" @tap="toOpenShop">

                                               
                                                 
                                                        <image :src="require('./_static/images/personal_icon_06.png')" />
                                                        <text>申请开店</text>
                                          
                                             </view>
                                             <view class="item" @tap="toManage"  v-if="orderInfo.salonState == 2">
                                                      <image :src="require('./_static/images/personal_icon_04.png')" />
                                                         <text>店铺管理</text>
                                             </view>

                                               <view class="item"  @tap="quit">
                                                 <image :src="require('./_static/images/personal_icon_05.png')" />
                                                 <text>退出登录</text>
                                            </view>

                                    </view>

                           
                                

                            
                  
                    

        
            </view>
    </view>
</block>    
</template>
<script>


import UsrInfo from './_components/usrInfo'
import Recode from './_components/recode'
import { postMyinformation , postPushArticle} from '@/request/actions';
//
export default {
   
    data(){
        return{
            user_id:null,
            user_type:'',
            islogin:false ,
            orderInfo:{},
            topart:{}
        }
       
       
    },
    components:{
    
        UsrInfo,
        Recode
  
    },
    methods:{

     
        tobeautyAllOrder(id){
            uni.reLaunch({
                url:`/pages/userbeautyOrderList/index?id=${id}`
            })
        },
            quit(){
                
                uni.showModal({
            
                    content: '是否确定退出',
                    success:res=> {
                        if (res.confirm) {
                           
                               getApp().globalData.userInfo = {};
                                
                                uni.removeStorage({
                                    key:'userInfo'
                                })

                                this.orderInfo = {};
                                this.islogin = false;
                               //  this.$broadcast('setInfo',{})
                              //   this.onShow();
                                 
                            

                        } 
                    }
               }) 

            },
            toOpenShop(){
                
                let {salonState} =  this.orderInfo;
                 uni.navigateTo({
                    url:`/pages/openShop/index?salonState=${salonState}`
                })
            },
            toManage(){
                 let {salonId} =  this.orderInfo;
          
                 uni.navigateTo({
                    url:`/pages/storeManage/index?salonId=${salonId}`
                })
            },
            loadData(){
                  let globalData = getApp().globalData;
                    if(Object.keys( globalData.userInfo).length == 0){

                            this.orderInfo = {};
                            this.islogin = false;
                        
                        }else{
                            
                                let {userId:userid} = globalData.userInfo;
                                
                                postMyinformation({userid}).then(r=>{
                                        let { data:res } = r;
                                        if(res.status == 200){
                                            
                                            this.orderInfo = res.data;  
                                            globalData.salonId = res.data.salonId;
                                            this.islogin = true;
                                        
                                        
                                        }
                            
                                    
                                    
                                })
                        }
            }
    },
   
    onLoad(){
       
           
         postPushArticle().then(r=>{
             let {data:res} = r;
             if(res.status == 200){
               
                     this.topart = res.data.article[0];
             }
            
        })
        


    },

    onShow(){
      this.loadData();
    },
      onPullDownRefresh(){
                this.loadData();
                uni.stopPullDownRefresh();
        }
 
} 

</script>
<style lang="scss">
     @import './_static/scss/personal.scss';  
</style>